import io
import ddddocr
from PIL import Image,ImageDraw,ImageFont
from fontTools.ttLib import TTFont
ocr = ddddocr.DdddOcr(show_ad=False)
font_maps = {}
font = TTFont("./static/font/file")
img_font = ImageFont.truetype("./static/font/file")

for code,name in font.getBestCmap().items():
    print(chr(code),name)
    if code == 120:
        continue
    else:
        img = Image.new("RGB", (35, 35), (255, 255, 255))

        draw = ImageDraw.Draw(img)
        draw.text((10,10), chr(code), (0, 0, 0), font=img_font)
        # img.save(f"./static/font/img/{code}.png", "png")

        img_bytes = io.BytesIO()
        img.save(img_bytes, "png")
        img_value = img_bytes.getvalue()

        r = ocr.classification(img_value)

        # print(code,r)
        font_maps[chr(code)] = r
print(font_maps)